package com.siyu.tickets.manager.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.siyu.common.page.Pagination;
import com.siyu.tickets.dao.PartnerDao;
import com.siyu.tickets.dao.PayFlowDao;
import com.siyu.tickets.dao.TicketVerifyDao;
import com.siyu.tickets.entity.Partner;
import com.siyu.tickets.entity.PayFlow;
import com.siyu.tickets.manager.FinanceMng;

@Service
@Transactional
public class FinanceMngImpl implements FinanceMng {

	@Override
	public Pagination getPartnerPayFlowPage(Partner partner, String type, Date beginTime, Date endTime, int pageNo,
			int pageSize) {
		return payFlowDao.getPage(partner.getId(), null, type, beginTime, endTime, pageNo, pageSize);
	}

	public PayFlow recharge(PayFlow flow) {
		// 更新分销商余额
		Partner partner = partnerDao.findById(flow.getUser().getId());
		partner.setMoney(partner.getMoney().add(flow.getMoney()));

		Date now = new Date();
		flow.setAction("recharge");
		flow.setCreateTime(now);
		return payFlowDao.save(flow);
	}

	public Pagination getTicketVerifyPage(Integer supplierId, Date beginTime, Date endTime, int pageNo, int pageSize) {
		return ticketVerifyDao.getPage(supplierId, beginTime, endTime, pageNo, pageSize);
	}

	@Autowired
	private PayFlowDao payFlowDao;

	@Autowired
	private PartnerDao partnerDao;

	@Autowired
	private TicketVerifyDao ticketVerifyDao;

}
